<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
<div>发送消息：</div>
<input type="text" id="msgContent" />
<input type="button" value="点我发送" onclick="CHAT.chat()" />

<div>接受消息：</div>
<div id="receveMsg" style="background-color: gainsboro;"></div>

<script type="application/javascript">

			window.CHAT={
				socket:null,
				init: function(e){
				    console.log(e);
					if(window.WebSocket){
					CHAT.socket=new WebSocket("ws://127.0.0.1:8088/ws")
					CHAT.socket.onmessage=function(e){
					    console.log("接收到消息")
						var receiveMsg=document.getElementById("receveMsg");
						var html=receiveMsg.innerHTML;
						console.log(e.data);
						receiveMsg.innerHTML=html+"<br/>"+e.data;
					}

					}else{
						alert("浏览器不支持")
					}

				},
				chat: function(){
					var msg=document.getElementById("msgContent");
					console.log(msg.value);
					CHAT.socket.send(msg.value)

				}
			}
			CHAT.init("初始化socket")
		</script>

</body>
</html>
